﻿namespace Common
{
    using System;
    using System.Web;
    using System.Xml;

    public class CXmlReader
    {
        private XmlNodeList GetNodes(string xmlName, string NodeName)
        {
            XmlDocument document = new XmlDocument();
            document.Load(HttpContext.Current.Server.MapPath(HttpContext.Current.Request.ApplicationPath + "/" + xmlName));
            return document.SelectNodes(NodeName);
        }

        private string GetNodeValue(System.Xml.XmlNode node, string key)
        {
            string str = string.Empty;
            for (int i = 0; i < node.Attributes.Count; i++)
            {
                string name = node.Attributes[i].Name;
                if ((name != null) && (string.IsInterned(name) == key))
                {
                    return node.Attributes[i].Value;
                }
            }
            return str;
        }

        private System.Xml.XmlNode GetSingleNode(string xmlName, string singleNodeName)
        {
            XmlDocument document = new XmlDocument();
            document.Load(HttpContext.Current.Server.MapPath(HttpContext.Current.Request.ApplicationPath + "/" + xmlName));
            return document.SelectSingleNode(singleNodeName);
        }

        public string GetSingleNodeValue(string xmlName, string singleNodeName, string key)
        {
            System.Xml.XmlNode singleNode = this.GetSingleNode(xmlName, singleNodeName);
            return this.GetNodeValue(singleNode, key);
        }
    }
}

